package com.example.my02

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.my02.ui.theme.My02Theme
import kotlin.contracts.contract

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            My02Theme {
                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                    Greeting(
                        name = "Android",
                        modifier = Modifier.padding(innerPadding)
                    )
                }
            }
        }
    }
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
    val img = painterResource(R.drawable.ic_launcher_background)

    Column(
        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = modifier.fillMaxSize()
    )  {

        Spacer(modifier = Modifier.height(200.dp))

        Column(
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = modifier
                .fillMaxWidth()
                .weight(1f, false)
        ) {
            Image(
                painter = img,
                contentDescription = null,
                //            contentScale = ContentScale.Crop,
                alpha = 0.4F,
                modifier = Modifier
                    .padding(vertical = 10.dp)
                    .clip(CircleShape)
            )
            Text(
                text = "Hello $name!",
                textAlign = TextAlign.Center,
                fontSize = 50.sp,
                lineHeight = 50.sp,
                modifier = Modifier.padding(vertical = 10.dp)
            )
            Text(
                text = "应用开发",
                fontSize = 30.sp,
                lineHeight = 30.sp,
                modifier = Modifier.padding(vertical = 10.dp)
            )
        }

        Spacer(modifier = Modifier.height(100.dp))

        Column(verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = modifier
                .fillMaxWidth()
                .weight(1f, false)) {
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp)
                )
                Text(
                    text = "+000000000",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp))
                Text(
                    text = "+222222222",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
            Row(horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.CenterVertically,
                modifier = Modifier.padding(vertical = 5.dp)) {
                Icon(
                    painter = img,
                    contentDescription = null,
                    modifier = Modifier
                        .height(30.dp)
                        .width(30.dp))
                Text(
                    text = "+666666666",
                    textAlign = TextAlign.Center,
                    fontSize = 20.sp,
                    lineHeight = 20.sp,
                    modifier = Modifier)
            }
        }
    }
}

@Composable
fun GreeetingImage()
{
    val img = painterResource(R.drawable.androidparty)
   Box {
        Image(
            painter = img,
            contentDescription = null
        )
        Greeting("Android")
    }
}

        @Preview(showBackground = true)
@Composable
fun GreetingPreview() {
    My02Theme {
       // Greeting("Android")
        GreeetingImage()
    }
}